import java.util.Arrays;

public class MyStack {
    private int[] elem;
    private int usedSize;
    private static final int DEFAULT_CAPACITY = 10;

    public MyStack() {
        this.elem = new int[DEFAULT_CAPACITY];
    }

    public void push(int val){
        if(isFull()){
            this.elem = Arrays.copyOf(this.elem, 2 * this.elem.length);
        }
        this.elem[usedSize] = val;
        this.usedSize++;
    }
    private boolean isFull(){
        return this.usedSize == this.elem.length;
    }

    public int pop(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");
        }
        int oldValue = this.elem[this.usedSize- 1];
        this.usedSize--;
        return oldValue;
    }

    public int peek(){
        if(isEmpty()){
            throw new RuntimeException("栈为空");
        }
        return this.elem[this.usedSize - 1];
    }

    public boolean isEmpty(){
        return this.usedSize == 0;
    }
}
